package com.tutou.mcpclientdemo.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/chat")
public class AIController {

    final ChatClient chatClient;


    @PostMapping("/single")
    public String chat(@RequestParam("msg") String msg) {
        return chatClient.prompt()
                // 用户的问题
                .user(msg)
                // 添加会话ID 到上下文
                .advisors(a -> a.param(AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY, "1"))
                .call().content();
    }

}

